cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB LIB_SOURCES
    *.cpp
    isa/*.cpp
    cachesim/*.cpp
    editor/*.cpp
    syscall/*.cpp
    version/version.cpp
    assembler/*.cpp
    io/*.cpp
    utilities/*.cpp)
file(GLOB LIB_HEADERS
    *.h
    isa/*.h
    cachesim/*.h
    editor/*.h
    syscall/*.h
    graphics/*.h
    assembler/*.h
    io/*.h
    utilities/*.h)
file(GLOB LIB_UIS
    *.ui
    cachesim/*.ui
    syscall/*.ui
    io/*.ui
)

set(RIPES_LIB ripes_lib)
add_library(${RIPES_LIB} ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UIS})
target_include_directories (${RIPES_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(${RIPES_LIB} PRIVATE cxx_std_17)

# Link external libraries
target_link_libraries(${RIPES_LIB} PUBLIC fancytabbar_lib)
target_link_libraries(${RIPES_LIB} PUBLIC ${VSRTL_GRAPHICS_LIB} Qt5::Charts)

add_subdirectory(processors)

# -----------------------------------------------------------------------------
# Version control file
# A file gen_versionnumber.h is generated by version.cmake, containing information
# regarding the current .git revision.
# This information is embedded into the binary for future reference, ie. for issue
# reporting.
add_custom_target(
    version_file ALL
    # Depend on the dummy file (which is not generated by the versioning script)
    # to ensure that the custom command is executed each time the project is built.
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version/dummy.cpp
    )

add_dependencies(${RIPES_LIB} version_file)

add_custom_command(
    OUTPUT
        # Dummy file not generated by the sript, but may be used as a dependency
        ${CMAKE_CURRENT_BINARY_DIR}/version/dummy.cpp
    COMMAND
        ${CMAKE_COMMAND}
            -DRIPES_SRC_DIR=${CMAKE_SOURCE_DIR}
            -P ${CMAKE_CURRENT_SOURCE_DIR}/version/version.cmake)
# Do not run AUTOMOC and AUTOUIC on the generated file (CMake warning)
# -----------------------------------------------------------------------------
